__author__ = 'Forcs'

def decode_url_query(query_str, separator='&', encoded=False, charset='utf-8'):
    arr = query_str.split(separator)
    if not arr:
        return {}
    query_dict = dict()
    for item in arr:
        if not item.find('='):
            continue
        kv = item.split('=')
        query_dict[kv[0]] = kv[1] if not encoded else kv[1].decode(charset)

    return query_dict
